package com.cn.sl.server.common.dto

import com.querydsl.core.types.dsl.BooleanExpression
import com.querydsl.core.types.dsl.DateTimePath
import io.swagger.v3.oas.annotations.media.Schema
import java.time.LocalDateTime

@Schema(description = "日期范围")
data class LocalDateTimeRangeDto(
    @field:Schema(description = "最小范围")
    override val min: LocalDateTime?,

    @field:Schema(description = "最大范围")
    override val max: LocalDateTime?
) : RangeAble<LocalDateTime, DateTimePath<LocalDateTime>> {
    
    override fun between(fieldPath: DateTimePath<LocalDateTime>): BooleanExpression {
        return if (this.min != null && this.max == null) {
            fieldPath.goe(this.min)
        } else if (this.min == null && this.max != null) {
            fieldPath.loe(this.max)
        } else {
            fieldPath.between(this.min, this.max)
        }
    }
}